<template>
  <Dialog
    v-model="dialogVisible"
    :title="dialogTitle"
    width="1200px"
    :scroll="true"
    maxHeight="200px"
  >
    <el-descriptions class="margin-top" title="患者基本信息" :column="4" :size="size" border>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">
            <!-- <el-icon :style="iconStyle">
              <user />
            </el-icon> -->
            姓名
          </div>
        </template>
        {{ formData.patientName }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">
            <!-- <el-icon :style="iconStyle">
              <postcard />
            </el-icon> -->
            证件号码
          </div>
        </template>
        {{ formData.idNumber }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">
            <!-- <el-icon :style="iconStyle">
              <male />
            </el-icon> -->
            性别
          </div>
        </template>
        {{ getDictLabel(DICT_TYPE.GENDER, formData.gender) }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">
            <!-- <el-icon :style="iconStyle">
              <calendar />
            </el-icon> -->
            出生年月
          </div>
        </template>
        {{ formatDate(formData.birthDate, 'YYYY-MM-DD') }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">
            <!-- <el-icon :style="iconStyle">
              <user />
            </el-icon> -->
            联系人姓名
          </div>
        </template>
        {{ formData.contactPerson }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">
            <!-- <el-icon :style="iconStyle">
              <iphone />
            </el-icon> -->
            联系人电话
          </div>
        </template>
        {{ formData.contactPhone }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">
            <!-- <el-icon :style="iconStyle">
              <office-building />
            </el-icon> -->
            上报状态
          </div>
        </template>
        <el-tag v-if="formData.reportStatus === '1'" type="primary">
          {{ getDictLabel(DICT_TYPE.REPORT_STATUS, formData.reportStatus) }}
        </el-tag>
        <el-tag v-if="formData.reportStatus === '2'" type="info">
          {{ getDictLabel(DICT_TYPE.REPORT_STATUS, formData.reportStatus) }}
        </el-tag>
        <el-tag v-if="formData.reportStatus === '3'" type="danger">
          {{ getDictLabel(DICT_TYPE.REPORT_STATUS, formData.reportStatus) }}
        </el-tag>
        <el-tag v-if="formData.reportStatus === '4'" type="success">
          {{ getDictLabel(DICT_TYPE.REPORT_STATUS, formData.reportStatus) }}
        </el-tag>
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">
            <!-- <el-icon :style="iconStyle">
              <office-building />
            </el-icon> -->
            上报时间
          </div>
        </template>
        {{ formatDate(formData.reportTime, 'YYYY-MM-DD') }}
      </el-descriptions-item>
            <el-descriptions-item :span="4">
        <template #label>
          <div class="cell-item">
            <!-- <el-icon :style="iconStyle">
              <location />
            </el-icon> -->
            家庭住址
          </div>
        </template>
        {{ formData.address }}
      </el-descriptions-item>
    </el-descriptions>
    <template #footer>
      <el-button @click="dialogVisible = false">取 消</el-button>
    </template>
  </Dialog>
</template>
<script lang="ts" setup>
import { DICT_TYPE, getIntDictOptions, getDictLabel } from '@/utils/dict'
import { formatDate } from '@/utils/formatTime'
import type { ComponentSize } from 'element-plus'
import * as townReportApi from '@/api/patient/reportManagement'
defineOptions({ name: 'ReportInfoDetail' })
const formData = ref({})
const { t } = useI18n() // 国际化
const message = useMessage() // 消息弹窗

const dialogVisible = ref(false) // 弹窗的是否展示
const dialogTitle = ref('') // 弹窗的标题

/** 打开弹窗 */
const open = async (id?: number) => {
  dialogVisible.value = true
  dialogTitle.value = t('action.detail')
  // 修改时，设置数据
  if (id) {
    formData.value = await townReportApi.getPatientDetail(id)
  }
}

const size = ref<ComponentSize>('default')

const iconStyle = computed(() => {
  const marginMap = {
    large: '8px',
    default: '6px',
    small: '4px'
  }
  return {
    marginRight: marginMap[size.value] || marginMap.default
  }
})

defineExpose({ open }) // 提供 open 方法，用于打开弹窗
</script>
<style lang="scss" scoped>
.el-descriptions {
  margin-top: 20px;
}
.cell-item {
  display: flex;
  align-items: center;
}
.margin-top {
  margin-top: 20px;
}
</style>
